Streaming | Some details about streaming and on-demand loading | |
Faster | What to do and what to avoid for maximum speed | |
Smaller | How to manage data in the most compact format |
As you can see in this overview, random-access and streaming can be mixed in three out of four ways. Once loaded, you can again save using either c4_Storage::Commit or c4_Storage::SaveToStream.
Saved using Loaded as Comments Commit
Commit
SaveToStream
SaveToStreamFile
Stream
File
StreamThe normal case, loads data on-demand
This combination is not allowed!
Ok, will load all data during open
Loads all data serially right away
When random-access and streaming are mixed on a storage object, the following will happen:
It is therefore possible to open a file, apply a few changes, save the
changed contents to a stream, and then close the file without committing
those changes. Streaming does not interfere with the commit/rollback mechanism.
When inserting several rows, consider inserting them all with a dummy value first, and then using a loop to adjust each of the inserted values.
The last two statements could also have been combined as "property (view[i]) = ...;"
Slow for (int i = 0; i < n; ++i)
{
c4_Row temp;
property (temp) = ...;
view[i] = temp;
}Faster c4_Row temp;
for (int i = 0; i < n; ++i)
{
property (temp) = ...;
view[i] = temp;
}Fastest for (int i = 0; i < n; ++i)
{
c4_RowRef row = view[i];
property (row) = ...;
}
Note that "prop1 [value1] + prop2 [value2]" also creates several temporary c4_Row objects, and should be avoided when top performance is critical.
In the first case, the view still exists as the storage object goes out of scope. There is a simple way to detach views from their storage objects, since they act merely as (reference-counted) pointers: just set "view = c4_View ();" before the storage object is destroyed.
Very slow
(on close){
c4_View view;
c4_Storage storage (...);
view = storage.View(...);
...
}Instant {
c4_Storage storage (...);
c4_View view = storage.View(...);
...
}
In this example, the view would use "adaptive integer sizing" even though its data is valid only for the duration of each run. Unattached views always use 32 bits to store integers.
c4_Storage storage;
c4_View view = storage.GetAt("temp[prop1:I,prop2:I]");
...
prop1 (view[i]) = ...;
...
For integers, the number of bits used to store values is determined as follows:
Value range Bits used Comments 0
0 .. 1
0 .. 3
0 .. 15
-128 .. 127
-32768 .. 32727
all others0
1
2
4
8
16
32If all rows are 0, no storage space is used
Booleans are stored as 8 rows per byte
Tiny positive codes
A hex nibble
One byte
A short integer
A long integer